package com.sas.web.articles;

import javax.swing.tree.DefaultMutableTreeNode;

import org.apache.wicket.Page;
import org.apache.wicket.markup.html.tree.ITreeStateListener;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;

import com.sas.domain.ArticleField;
import com.sas.model.EntityModel;
import com.sas.web.panel.articles.ArticleFieldTreePanel;

public class ArticlesPageListener extends Page implements ITreeStateListener {

	private ArticleFieldTreePanel aftp;
	
	public ArticleFieldTreePanel getAftp() {
		return aftp;
	}

	public void setAftp(ArticleFieldTreePanel aftp) {
		this.aftp = aftp;
	}

	@Override
	public void allNodesCollapsed() {
		
	}

	@Override
	public void allNodesExpanded() {
		
	}

	@Override
	public void nodeCollapsed(Object node) {

	}

	@Override
	public void nodeExpanded(Object node) {
		
	}

	@Override
	public void nodeSelected(Object node) {
		//System.out.println("seleccione nodo: " + node);
		DefaultMutableTreeNode aux = (DefaultMutableTreeNode) node;
		ArticleField ret = (ArticleField) aux.getUserObject();
		
		//System.out.println(ret);
		
		final IModel<ArticleField> imodelArticleField = new EntityModel<ArticleField>(ArticleField.class, ret); 
		aftp.setSelectedArticleField(imodelArticleField);
		setResponsePage(new ArticlesPage(aftp));
	}

	@Override
	public void nodeUnselected(Object node) {
		
	}		
}